- page_title _("Labels")
- can_admin_label = can?(current_user, :admin_label, @project)
- search = params[:search]
- subscribed = params[:subscribed]
- archived = params[:archived]
- labels_or_filters = @labels.exists? || @prioritized_labels.exists? || search.present? || subscribed.present? || archived.present?
- add_page_specific_style 'page_bundles/labels'

%h1.gl-sr-only= page_title

- if Feature.enabled?(:labels_archive, :instance)
  = render 'shared/labels/nav', labels_or_filters: labels_or_filters, can_admin_label: can_admin_label

- if labels_or_filters
  #js-promote-label-modal
  - if Feature.disabled?(:labels_archive, :instance)
    = render 'shared/labels/nav', labels_or_filters: labels_or_filters, can_admin_label: can_admin_label

  - if can_admin_label && search.blank?
    %p.gl-text-subtle.gl-mt-5.gl-mb-0
      - if archived && Feature.enabled?(:labels_archive, :instance)
        = _('Archived labels are not available for use. Unarchive a label you want to use, or delete a label you want to permanently remove.')
      - else
        = _('Labels can be applied to issues and merge requests. Star a label to make it a priority label.')

  .labels-container.gl-flex.gl-flex-col.gl-gap-5.gl-mt-5
    -# Only show it in the first page and hide when viewing archived tab
    - hide = @available_labels.empty? || (params[:page].present? && params[:page] != '1') || (Feature.enabled?(:labels_archive, :instance) && params[:archived] == 'true')
    = render ::Layouts::CrudComponent.new(_('Prioritized labels'),
      options: {class: ['prioritized-labels', ('gl-hidden' if hide), ('is-not-draggable' unless can_admin_label)].compact.join(' ')},
      count: number_with_delimiter(@prioritized_labels.size),
      icon: 'label',
      body_options: { class: '!gl-m-0' },
      description: _('Drag to reorder prioritized labels and change their relative priority.')) do |c|
      - c.with_body do
        %ul.js-prioritized-labels.gl-rounded-base.manage-labels-list{ data: { url: set_priorities_project_labels_path(@project), sortable: can_admin_label } }
          %li#js-priority-labels-empty-state.priority-labels-empty-state.gl-list-none{ class: "#{'hidden' unless @prioritized_labels.empty? && search.blank?}" }
            = render 'shared/empty_states/priority_labels'
          - if @prioritized_labels.any?
            = render partial: 'shared/label', collection: @prioritized_labels, as: :label, locals: { force_priority: true, subject: @project }
          - elsif search.present?
            .nothing-here-block
              = _('No prioritized labels with such name or description')

    - if @labels.any?
      = render ::Layouts::CrudComponent.new(hide ? _('Labels') : _('Other labels'), options: { class: 'other-labels' }, count: number_with_delimiter(@labels.total_count), icon: 'label', body_options: { class: '!gl-m-0' }) do |c|
        - c.with_body do
          %ul.js-other-labels.manage-labels-list
            = render partial: 'shared/label', collection: @labels, as: :label, locals: { subject: @project }
        - c.with_pagination do
          = paginate @labels, theme: 'gitlab'

    - elsif search.present?
      .other-labels
        - if @available_labels.any?
          %h4
            = _('Other labels')
          .nothing-here-block
            = _('No other labels with such name or description')
        - else
          .nothing-here-block
            = _('No labels with such name or description')
    - elsif subscribed.present?
      .nothing-here-block
        = _('You do not have any subscriptions yet')
    - elsif archived.present?
      .nothing-here-block
        = _('No archived labels')
- else
  = render 'shared/empty_states/labels'
